﻿using Hsp.Auto.Interface;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Hsp.Auto.Oracle
{
    public class OracleHelper : DataHelper, IDbHelper
    {
        //static OracleHelper()
        //{
        //}

        #region 泛型方法查询实体数据

        /// <summary>
        /// 根据属性类型获取字段名称
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        internal static string GetFiledsByType(Type type)
        {
            // User是关键字，因此要包成[User]
            return string.Join(',', type.GetProperties().Select(p => '[' + p.Name + ']'));
        }

        /// <summary>
        /// 泛型方法查询数据实体
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="id">id</param>
        /// <returns></returns>
        public T SingleQuery<T>(int id)
        {
            return default;
        }
        /// <summary>
        /// 泛型方法查询数据实体
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="id">id</param>
        /// <returns></returns>
        public T SingleQuery<T>(string id)
        {
            return default;
        }

        /// <summary>
        /// 泛型方法查询数据实体
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="id">id</param>
        /// <returns></returns>
        public T SingleQuery<T>(Guid id)
        {
            return default;
        }

        #endregion

        #region 泛型方法查询列表数据

        /// <summary>
        /// 泛型方法查询数据列表
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <returns></returns>
        public List<T> ListQuery<T>()
        {
            Type type = typeof(T); // User是关键字，因此要包成[User]
            var strSql = $"SELECT {GetFiledsByType(type)} FROM [{type.Name}] ;";
            return this.ListQuery<T>(strSql);
        }

        /// <summary>
        /// 泛型方法查询数据列表
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="strSql">数据库脚本</param>
        /// <returns></returns>
        public List<T> ListQuery<T>(string strSql)
        {
            return new List<T>();
        }

        #endregion

        #region SqlNull

        public static object SqlNull(object obj)
        {
            return obj == null || obj.ToString() == "" ? DBNull.Value : obj;
        }

        #endregion

        #region 泛型数据库增删改
        public int Add<T>(T t)
        {
            throw new NotImplementedException();
        }

        public int Delete<T>(int id)
        {
            throw new NotImplementedException();
        }

        public int Update<T>(T t)
        {
            throw new NotImplementedException();
        }

        public T SingleWhereQuery<T>(string sqlwhere)
        {
            throw new NotImplementedException();
        }

        public int DeleteByWhereSql<T>(string sqlwhere)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
